﻿using System;
using System.ComponentModel;

namespace Esponce.QRCode.Models
{
	public class DateRecord : IRecord, INotifyPropertyChanged
	{
		#region Public properties
		/// <summary>
		/// Gets or sets date of groupped records.
		/// </summary>
		public DateTime Date
		{
			get
			{
				return this.date;
			}
			set
			{
				if (this.date != value)
				{
					this.date = value;
					OnPropertyChanged("Date");
					OnPropertyChanged("Name");
					OnPropertyChanged("Day");
					OnPropertyChanged("Month");
					OnPropertyChanged("Year");
				}
			}
		}
		private DateTime date;

		/// <summary>
		/// Gets or sets number of records in the group.
		/// </summary>
		public int Count
		{
			get
			{
				return this.count;
			}
			set
			{
				if (this.count != value)
				{
					this.count = value;
					OnPropertyChanged("Count");
				}
			}
		}
		private int count;

		/// <summary>
		/// Gets time formatted as "yyyy-MM-dd"
		/// </summary>
		public string Name
		{
			get
			{
				return this.Date != null ? this.Date.ToString("yyyy-MM-dd") : null;
			}
			set
			{
				//Not handled here but required by IRecord
			}
		}

		/// <summary>
		/// Gets day of month.
		/// </summary>
		public int Day
		{
			get
			{
				return this.Date.Day;
			}
		}

		/// <summary>
		/// Gets month number (1..Jan, 2..Feb, etc.)
		/// </summary>
		public int Month
		{
			get
			{
				return this.Date.Month;
			}
		}

		/// <summary>
		/// Gets year number.
		/// </summary>
		public int Year
		{
			get
			{
				return this.Date.Year;
			}
		}
		#endregion

		#region INotifyPropertyChanged Members
		public event PropertyChangedEventHandler PropertyChanged;
		protected virtual void OnPropertyChanged(string propertyName)
		{
			if (PropertyChanged != null)
			{
				PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
			}
		}
		#endregion
	}
}
